﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;

namespace CAGFIP.Jogo
{
    internal class TimerJogo
    {
        #region Fields

        ControladorJogo cj;
        Timer timer;
        double interval;

        #endregion

        #region Constructors

        public TimerJogo(ControladorJogo cj)
        {
            if (cj == null) throw new ArgumentNullException("cj");
            this.cj = cj;
        }

        #endregion

        #region Properties

        private ControladorJogo Cj
        {
            get { return this.cj; }
        }

        private double Interval
        {
            get { return this.interval; }
            set { this.interval = value; }
        }

        private Timer Timer
        {
            get
            {
                if (this.timer == null)
                {
                    this.timer = new Timer();
                }
                return this.timer;
            }
            set { this.timer = value; }
        }

        #endregion

        #region Methods

        public void Configure(double interval)
        {
            Interval = Timer.Interval = interval;
            //Timer.Elapsed += cj;
        }

        public void Enable()
        {
            Timer.Enabled = true;
        }
        public void Disable()
        {
            Timer.Enabled = false;
        }

        public void Reset()
        {
            if (this.timer != null)
            {
                this.timer.Close();
                this.timer = null;
            }
            Configure(Interval);
        }

        #endregion
    }
}
